﻿#ifndef __DefaultWorkQueueStandard_H__
#define __DefaultWorkQueueStandard_H__
#include "kernel/threading/workqueue.h"

namespace FD
{
        namespace Kernel
        {
            /** Implementation of a general purpose request / response style background work queue.
            @remarks
            	This default implementation of a work queue starts a thread pool and
            	provides queues to process requests.
            */
            class FD_Kernel_Export CDefaultWorkQueue : public FD::Kernel::DefaultWorkQueueBase
            {
            public:
                CDefaultWorkQueue(const String &name);
                CDefaultWorkQueue();
                virtual ~CDefaultWorkQueue();
            public:
                //static CDefaultWorkQueue* getSingletonPtr();
                //static CDefaultWorkQueue& getSingleton();
                
            protected:
                //static CDefaultWorkQueue* mpSingleton;    
                void init();
				
            public:
                //// Main function for each thread spawned.
                virtual void _threadMain();
                //// @copydoc WorkQueue::shutdown
                virtual void shutdown();
                //// @copydoc WorkQueue::startup
                virtual void startup(bool forceRestart);
                virtual void startup();

				virtual bool isQueueRunningByFilter(UINT16 channel,UINT64 filter);
            public:
                /** To be called by a separate thread; will return immediately if there
                	are items in the queue, or suspend the thread until new items are added
                	otherwise.
                */
                virtual void waitForNextRequest();
                //// Notify that a thread has registered itself with the render system
                virtual void notifyThreadRegistered();
                virtual void notifyWorkers();
            protected:
                size_t mNumThreadsRegisteredWithRS;
                //// Init notification mutex (must lock before waiting on initCondition)
                OGRE_MUTEX(mInitMutex)
                //// Synchroniser token to wait / notify on thread init
                OGRE_THREAD_SYNCHRONISER(mInitSync)
                OGRE_THREAD_SYNCHRONISER(mRequestCondition)
#if OGRE_THREAD_SUPPORT
                typedef vector<OGRE_THREAD_TYPE *> WorkerThreadList;
                WorkerThreadList mWorkers;
#endif
            };
        }
}

#endif

